"""
ECS核心组件定义
"""
from dataclasses import dataclass
from typing import Tuple, Dict, Any
import pygame
from .entity import Component

@dataclass
class Transform(Component):
    """变换组件"""
    x: float = 0.0
    y: float = 0.0
    rotation: float = 0.0
    scale: float = 1.0

@dataclass
class Renderable(Component):
    """可渲染组件"""
    sprite: pygame.Surface = None
    visible: bool = True
    layer: int = 0  # 渲染层级

@dataclass
class Physics(Component):
    """物理组件"""
    velocity_x: float = 0.0
    velocity_y: float = 0.0
    collider: pygame.Rect = None
    is_static: bool = False

@dataclass
class Health(Component):
    """生命值组件"""
    current: int = 100
    max: int = 100
    invincible: bool = False
    invincible_timer: float = 0.0

@dataclass
class PlayerControl(Component):
    """玩家控制组件(支持双人)"""
    up_key: int = pygame.K_w
    down_key: int = pygame.K_s
    left_key: int = pygame.K_a
    right_key: int = pygame.K_d
    fire_key: int = pygame.K_SPACE  # 新增开火键
    speed: float = 5.0
    player_id: int = 1  # 玩家ID (1或2)

@dataclass
class Weapon(Component):
    """武器组件"""
    damage: int = 1
    cooldown: float = 1.0
    last_attack_time: float = 0.0
    projectile_speed: float = 10.0
    owner_id: int = -1  # 拥有者实体ID

@dataclass
class Score(Component):
    """分数组件"""
    value: int = 0
    player_id: int = 1  # 玩家ID (1或2)

@dataclass
class AI(Component):
    """AI组件"""
    behavior_type: str = "wander"
    target_id: int = -1  # 目标实体ID
    detection_range: float = 200.0
    wander_speed: float = 2.0  # 添加徘徊速度

@dataclass
class StateTimer(Component):
    """状态计时器组件"""
    state_name: str = ""  # 状态名称（如"invincible"）
    duration: float = 0.0  # 状态持续时间
    remaining: float = 0.0  # 状态剩余时间

# ====== 新增组件 ======
@dataclass
class Relation(Component):
    """实体关系组件"""
    relations: dict  # 存储实体间关系，如{"opponent": entity_id}
    relations: Dict[str, int] = None  # 关系类型 -> 目标实体ID

@dataclass
class EventData(Component):
    """事件数据组件"""
    event_type: str = ""
    event_data: Dict[str, Any] = None